home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / Mandlebrot / Mandlebrot Folder / Event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-09  |  6.1 KB  |  246 lines  |  [TEXT/KAHL]

  1. /* *********************************************************************************
  2.      
  3.       FILE:            Event.c
  4.       
  5.      DESCRIPTION:    Event loop called from inside drawMandel at the end of each 
  6.                      horizontal line.  Checks for mouse position, close box, grow box, 
  7.                      the various combinations of control, apple, shift and option keys 
  8.                      and menu selects. 
  9.                       
  10.      AUTHOR:        Bruce E. Gladstone
  11.      
  12.      Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
  13.      
  14.      Revision History:
  15.      ============================================================
  16.      5/1/90    - Release to Compuserve
  17.      ============================================================
  18.      
  19.      COMMENTS:
  20.      
  21.      None. 
  22.  
  23.    ******************************************************************************** */        
  24.  
  25. #include <stdio.h> 
  26. #include <MacTypes.h> 
  27. #include <WindowMgr.h>
  28. #include <MenuMgr.h>
  29. #include <EventMgr.h>
  30. #include <ToolboxUtil.h> 
  31. #include <ControlMgr.h>
  32. #include <color.h>
  33. #include <colortoolbox.h>
  34. #include "Mandelbrot.h"
  35.  
  36.  
  37. /* ---------------------------- Global Variables ---------------------------------- */
  38.  
  39. extern int                colorQD;
  40. extern int                quitFlag;
  41. extern int                linearFlag;
  42. extern int                custPict;
  43. extern int                numColorBits;
  44. extern int                numColors, brushSize;
  45. extern int                limit;
  46. extern int                n;
  47. extern long                startTime, now;
  48. extern float            res;
  49. extern float            centx, centy;
  50. extern float            xmin, xmax, ymin, ymax;
  51. extern float            delx, dely;
  52.  
  53. /* ---------------------------- Global MacTypes ----------------------------------- */
  54.  
  55. extern Str255            str;
  56. extern CTabHandle        myColorHandle;
  57. extern RGBColor            aColor;
  58. extern Rect                myRect, dragRect;
  59. extern WindowPtr        aboutWindow;        
  60. extern MenuHandle        appleMenu, mandelMenu, editMenu, xMenu, yMenu, resMenu, timeMenu;
  61. extern WindowPtr        myWindow;
  62.  
  63. /* ---------------------------  Local Prototypes  --------------------------------- */
  64.  
  65. int eventCheck ( void );
  66. void doMenu ( long );
  67.  
  68. /* --------------------------------------------------------------------------------
  69.     eventCheck - 5/01/90 beg
  70.    -------------------------------------------------------------------------------- */
  71.  
  72. int
  73. eventCheck ()
  74. {
  75.     int            zIn, zOut;
  76.     char        theChar;
  77.     int            myPart;
  78.     int         result, stillInGoAway;
  79.     EventRecord    myEvent;
  80.     WindowPtr    whichWindow;
  81.     long        windSize;
  82.     
  83.     result = FALSE;
  84.     if ( GetNextEvent ( everyEvent, &myEvent )) 
  85.     {
  86.         switch ( myEvent.what ) 
  87.         {    
  88.             case activateEvt:    
  89.             case app4Evt:
  90.                 if ( colorQD )
  91.                 {
  92.                     numColorBits = (**(*(CGrafPtr)myWindow).portPixMap).pixelSize;
  93.                     numColors = 1 << numColorBits;
  94.                     result = TRUE;
  95.                     break;
  96.                 }
  97.             case keyDown:
  98.             case autoKey:
  99.                 if ( ! ( myEvent.modifiers & cmdKey ))
  100.                 {
  101.                     result = TRUE;
  102.                     break;
  103.                 }
  104.                 if ( myWindow == FrontWindow ()) 
  105.                 {
  106.                     theChar = myEvent.message & charCodeMask;
  107.                     if ( theChar == 'q' || theChar == 'Q' )
  108.                         ExitToShell();
  109.                 }
  110.             case mouseDown:
  111.             myPart = FindWindow ( myEvent.where, &whichWindow );
  112.             switch ( myPart ) 
  113.             {
  114.                 case inMenuBar:
  115.                     doMenu ( MenuSelect ( myEvent.where ));
  116.                     result = TRUE;
  117.                     break;
  118.                 case inSysWindow:
  119.                     SystemClick ( &myEvent, whichWindow );
  120.                     if ( colorQD )
  121.                     {
  122.                         numColorBits = (**(*(CGrafPtr)myWindow).portPixMap).pixelSize;
  123.                         numColors = 1 << numColorBits;
  124.                         result = TRUE;
  125.                         break;
  126.                     }
  127.                 case inContent:
  128.                     if (whichWindow != FrontWindow())
  129.                     {
  130.                         HiliteWindow ( whichWindow, TRUE );
  131.                     }
  132.                     else if ( whichWindow == myWindow )
  133.                     {
  134.                         zIn =  ( myEvent.modifiers & cmdKey );
  135.                         zOut = ( myEvent.modifiers & optionKey );
  136.                         if ( zOut != 0 && zIn == 0 )
  137.                         {
  138.                             res = res*2;
  139.                         }
  140.                         if ( zIn != 0 && zOut == 0 )
  141.                         {
  142.                             switch ( custPict ) 
  143.                             {
  144.                                 case 1:
  145.                                     centx = -0.55;
  146.                                     centy =  0.60;
  147.                                     res   =  0.10;
  148.                                     custPict = 2;
  149.                                     break;
  150.                                 case 2:
  151.                                     centx = -0.92;
  152.                                     centy =  0.26;
  153.                                     res   =  0.03;
  154.                                     custPict = 3;
  155.                                     break;
  156.                                 case 3:
  157.                                     centx = -1.253;
  158.                                     centy =  0.046;
  159.                                     res   =  0.001;
  160.                                     custPict = 4;
  161.                                     break;
  162.                                 case 4:
  163.                                     centx = -1.25316;
  164.                                     centy =  0.0465;
  165.                                     res   =  0.0005;
  166.                                     custPict = 5;
  167.                                     break;
  168.                                 case 5:
  169.                                     centx = -0.747;
  170.                                     centy =  0.106;
  171.                                     res   =  0.001;
  172.                                     custPict = 6;
  173.                                     break;
  174.                                 case 6:
  175.                                     centx = -0.74543;
  176.                                     centy =  0.11301;
  177.                                     res   =  0.00001;
  178.                                     custPict = 1; 
  179.                                     break;
  180.                             }
  181.                             result = TRUE;
  182.                             break;
  183.                         }
  184.                         if ( zIn != 0 && zOut != 0 )
  185.                         {
  186.                             centx = -0.8;
  187.                             centy =  0.0;
  188.                             res   =  1.0;
  189.                             result = TRUE;
  190.                             break;
  191.                         }
  192.                         if ( myEvent.modifiers & shiftKey )
  193.                         {
  194.                         res = 0.5*res;
  195.                         }
  196.  
  197.                         GlobalToLocal ( &myEvent.where );
  198.                         centx = xmin + delx * (  myEvent.where.h );
  199.                         centy = ymin + delx * (  myEvent.where.v ); 
  200.                         result = TRUE;    
  201.                         break;    
  202.                     }
  203.                 case inDrag:
  204.                     DragWindow ( whichWindow, myEvent.where, &dragRect );
  205.                     result = TRUE;
  206.                     break;
  207.                 case inGrow:
  208.                     windSize = GrowWindow ( whichWindow, myEvent.where, &dragRect );
  209.                     SizeWindow ( whichWindow, LoWord ( windSize ), HiWord
  210.                         ( windSize ), TRUE );
  211.                     myRect = (*myWindow).portRect;
  212.                     ClipRect ( &myRect );
  213.                     FillRect ( &myRect, white );
  214.                     result = TRUE;
  215.                     break;        
  216.                 case inGoAway:
  217.                     stillInGoAway = TrackGoAway ( whichWindow, myEvent.where );
  218.                     if ( stillInGoAway )
  219.                     {
  220.                         CloseWindow ( whichWindow );
  221.                         ExitToShell();
  222.                     }
  223.                 case inZoomIn:
  224.                 case inZoomOut:
  225.                     if ( TrackBox ( whichWindow, myEvent.where, myPart ))
  226.                     {
  227.                          ZoomWindow ( whichWindow, myPart, FALSE );
  228.                         myRect = (*myWindow).portRect;
  229.                         ClipRect ( &myRect );
  230.                         FillRect ( &myRect, white );
  231.                         result = TRUE;
  232.                         break;
  233.                     }
  234.             }
  235.             default:
  236.                 return ( result );
  237.         }
  238.     }
  239.     return ( result );
  240. }   /*  eventCheck ()  */
  241.  
  242. /* ===============================  EOF  ==========================================
  243.     Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
  244.    ================================================================================ */
  245.  
  246.